{	Problem: http://codeforces.ru/problemset/problem/51/A
 	Verdict: Accepted
}
var s,s1:string; i,n,c:longint; a:array['1'..'6','1'..'6','1'..'6','1'..'6'] of boolean;
begin
fillchar(a,sizeof(a),false);
readln(n);
for i:=1 to n do begin
  readln(s);
  readln(s1);
  if (not a[s[1]][s[2]][s1[2]][s1[1]]) and (not a[s1[1]][s[1]][s[2]][s1[2]]) and (not a[s1[2]][s1[1]][s[1]][s[2]]) and (not a[s[2]][s1[2]][s1[1]][s[1]]) then begin
    inc(c);
    a[s[1]][s[2]][s1[2]][s1[1]]:=true;
  end;
  readln;
end;
write(c);
end.